在真實世界中,大家都很愛比較,我比你有錢,
我長得比你高,我比你帥,
我比你漂亮,C#世界也是非常愛比較的

運算子 | 用途 |  類別
------------- | -------------
|< | 小於 | 二元
|> | 大於 | 二元
|<= | 小於等於 | 二元
|>= | 大於等於 | 二元
|==| 等於 | 二元
|!=| 不等於 | 二元
注意! 各位千萬不要把 " == " 與 " = "搞混了,前者是比較,後者是賦值

| 邏輯表達式 | 結果 | 
|---|---|
| 1 < 2 | 真 | 
| 3 > 2 | 真 | 
| 4 == 5 | 假 | 
| (6 / 2) != 3 | 假 | 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //直接印出結果
            Console.WriteLine(1 < 2);
            Console.WriteLine(3 > 2);
            Console.WriteLine(4 == 5);
            Console.WriteLine((6 / 2) != 3);
            Console.ReadKey();
        }
    }
}
結果:
True
True
False
False

裡頭包含了:
&& 且 (and)|| 或 (or)! 非 (not)&& 且 (and) :兩者條件都要滿足P | Q |  P and Q
------------- | -------------
|true | true | true
|true | false | false
|false | true | false
|false | false | false

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //宣告x為12
            int x = 12;
            //x要大於10,因為是偶數所以可以被2整除
            Console.WriteLine((x > 10) && (x % 2 == 0));
            Console.ReadKey();
        }
    }
 }
結果:
True
|| 或 (or):其中之一滿足則成立P | Q |  P and Q
------------- | -------------
|true | true | true
|true | false | true
|false | true | true
|false | false | false

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //宣告x為12
            int x = 12;
            //x是正數,但x是三的倍數
            Console.Write("x = " + x+" , ");
            Console.WriteLine((x < 10) || (x % 3 == 0));
            //x是負數,但x不是三的倍數
            x = -10;
            Console.Write("x = " + x + " , ");
            Console.WriteLine((x < 10) || (x % 3 == 0));
            //x是正數,也x不是三的倍數
            x = 10;
            Console.Write("x = " + x + " , ");
            Console.WriteLine((x < 10) || (x % 3 == 0));
            Console.ReadKey();
        }
    }
 }
結果:
x = 12 , True
x = -10 , True
x = 10 , False
! 非 (not):與事實相反1 != 2 也可以使用 !(1 == 2) 表示
bool
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //宣告一個布林變數
            bool isEven;
            Console.WriteLine("來輸入一個整數吧!");
            int x = Convert.ToInt32(Console.ReadLine());
            //判斷是不是偶數
            isEven = (x % 2) == 0;
            //列印結果
            Console.Write("請問神奇一隻雞," + x + "是偶數嗎 ? ");
            Console.WriteLine(isEven);
            Console.ReadKey();
        }
    }
}
輸入:
10
結果:
來輸入一個整數吧!
10
請問神奇一隻雞,10是偶數嗎 ? True
輸入:
11
結果:
來輸入一個整數吧!
1
請問神奇一隻雞,1是偶數嗎 ? False